package com.ef.service.impl;

import java.util.List;

import com.ef.constant.StatusType;
import com.ef.dao.CompanyDao;
import com.ef.domain.Company;
import com.ef.service.CompanyService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class CompanyServiceImpl extends BaseServiceImpl implements
		CompanyService {

	private CompanyDao companyDao;

	public PaginationSupport<Company> findByExample(
			CustomExample<Company> example, int startIndex, int pageSize) {

		return companyDao.findPageByExample(example, startIndex, pageSize);
	}

	public void saveOrUpdate(Company company) {
		companyDao.saveOrUpdate(company);
	}

	public List<Company> findByAnything(String qitem, int max) {
		StringBuffer hql = new StringBuffer(
				"From Company where (lower(name) like '%");
		hql.append(qitem.trim().toLowerCase());
		hql.append("%') and status='VALID' ");
		return companyDao.findMultiAll(hql.toString(), 0, max);
	}

	public void delete(Company company) {
		company.setStatus(StatusType.INVALID);
		companyDao.update(company);
	}

	public Company findById(Long id) {
		return companyDao.findById(id);
	}

	public CompanyDao getCompanyDao() {
		return companyDao;
	}

	public void setCompanyDao(CompanyDao companyDao) {
		this.companyDao = companyDao;
	}

}
